function functionExists(func) {
	return (typeof func == 'function');
} 

function confirmDelete()
{
    return confirm("Are you sure you want to delete this entry?");
}

function browse_select(_form, _field, _value) {
  if (window.opener && !window.opener.closed){
	window.opener.document.forms[_form].elements[_field].value = _value;
	if (functionExists(window.opener.document.forms[_form].elements[_field].onchange)) {
		window.opener.document.forms[_form].elements[_field].onchange();
	}
    window.opener.focus();
  }
  window.close();
}

function print_r(object) {
	var output = '';
	for (property in object) {
	  output += property + ': ' + object[property]+'\n';
	}
	alert(output);
}

function viewPort(){
	this.windowX = (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || self.innerWidth || document.body.clientWidth;
	this.windowY = (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight;
	this.scrollX = (document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft;
	this.scrollY = (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop;
	this.pageX = (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth;
	this.pageY = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
}

function indoCurrencyFormatted(amount)
{
	var s = currencyFormatted(amount)+'';
	s = s.replace(/,/g, '?');
	s = s.replace(/\./g, ',');
	s = s.replace(/\?/g, '.');
	return s;
}

function currencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return commaFormatted(s);
}
// end of function CurrencyFormatted()

function commaFormatted(amount)
{
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}
// end of function CommaFormatted()

function refreshReadOnlyStyle(aform, afield) {
	if (document.forms[aform].elements[afield].readOnly) {
		document.forms[aform].elements[afield].style.backgroundColor="#DDDDDD";
	} else {
		document.forms[aform].elements[afield].style.backgroundColor="transparent";
	}
}
function toogleReadOnly(aform, afield) {
	document.forms[aform].elements[afield].readOnly = document.forms['input_form'].elements['_null_'+afield].checked;
	refreshReadOnlyStyle(aform, afield);
}
function updateBooleanCheckBox(aform, afield) {
	if (document.forms[aform].elements['_checkbox_'+afield].checked) {
		document.forms[aform].elements[afield].value = 1;
	} else {
		document.forms[aform].elements[afield].value = 0;
	}
	
}

function filter(aform, uri) {
	res = '';
	for (i=0; i<aform.elements.length; i++) {
		if (aform.elements[i].value.length > 0) {
			res = res + encode_for_uri(aform.elements[i].name) + '/' + encode_for_uri(aform.elements[i].value) + '/';
		}
	}
	window.location.href = uri+'/filter/by/'+res;
}